package com.pet.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pet.service.SysPetService;
import com.pet.system.SysPet;
import com.pet.system.SysUser;
import com.pet.utils.Result;
import com.pet.utils.VodTemplate;
import com.pet.vo.SysPetQueryVo;
import com.pet.vo.SysUserQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 宠物表 前端控制器
 * </p>
 *
 * @author whd
 * @since 2023-08-01
 */
@RestController
@Api(tags = "宠物前端控制器")
@RequestMapping("/lovePet/system/sysPet")
public class SysPetController {


    @Autowired
    private SysPetService sysPetService;



    @GetMapping("/findAllPet")
    public Result findAllPet() {
        List<SysPet> list = sysPetService.list();
        return Result.ok(list);
    }


    //分页和条件查询
    @ApiOperation("分页和条件查询")
    @PostMapping("{page}/{limit}")
    public Result selectUserPageByVo(@PathVariable Long page,
                                     @PathVariable Long limit,
                                     @ApiParam("包装的查询分类名称名称") @RequestBody SysPetQueryVo sysPetQueryVo) {
        System.out.println("=========" + sysPetQueryVo.getKeyword());
        IPage<SysPet> iPage = new Page<>(page, limit);
        iPage = this.sysPetService.selectpage(iPage, sysPetQueryVo);
        return Result.ok(iPage);
    }


    // 添加宠物
    @PostMapping("/addPet")
    public Result addPet(@RequestBody SysPet sysPet) {
        boolean b = this.sysPetService.save(sysPet);
        return b ? Result.ok() : Result.fail();
    }

    //根据id获取宠物
    @GetMapping("/findSysPetById/{id}")
    public Result findSysPetById(@PathVariable Long id) {
        SysPet sysPet = this.sysPetService.getById(id);
        return Result.ok(sysPet);
    }


    // 实现修改
    @PostMapping("/updateSysPet")
    public Result updateSysPet(@RequestBody SysPet sysPet) {
        boolean b = this.sysPetService.updateById(sysPet);
        return b ? Result.ok() : Result.fail();

    }

    @ApiOperation("根据id去移除一个宠物")
    @DeleteMapping("/removeSysPetById/{id}")
    public Result removeSysPetById(@PathVariable Long id) {
        boolean b = this.sysPetService.removeById(id);
        return b ? Result.ok() : Result.fail();
    }



}

